-
Couldn't load subscription status.
- Fork 277
Set socket to MAX_SOCK_NUM if connection fails #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@karlsoderby @per1234 , this is my first time contributing to the Arduino ecosystem. Please let me know if there's anything missing from the PR or anything else you'd like to see from me :) |
|
Memory usage change @ ec1ed04
Click for full report table
Click for full report CSV |
|
Hey @karlsoderby @per1234, bumping this. Is there anyway to move this PR forward? |
|
There is an alternative proposal at #176 |
I've been experiencing a bug using the Arduino to communicate over ethernet when using multiple EthernetClients, and as far as I can tell this line is the culprit. The exact steps of how the bug happens:
A.connect(HOST, PORT1);is called first. Inside theconnectfunction, the functionsocketBeginis called, which according to the code here finds the first unused socket number and returns it. Lets say in this case the first unused socket number is 0. This means thatA._socketIndexends up being 0.A.connect(HOST, PORT1);fails on line 63. However, note thatA._socketIndexis NOT reset back toMAX_SOCK_NUMand stays at the initialized value (for this example we'll stick with 0).B.connect(HOST, PORT2);is called second. The process as above happens, andB._socketIndexis set to 0. However, for some reasonB.connect(HOST, PORT2);works, and B is able to connect.B._socketIndex == A._socketIndex == 0. However, sinceA.connect(HOST, PORT1)returned 0 (which stands for false), calls toA.available(),A.read()shouldn't work. Instead, they do work, and even worseA.write()will write data to the socket that B is connected to.This change should fix the bug, because instead of returning 0 on line 63 we break, we set
_socketIndexback toMAX_SOCK_NUMand everything behaves as expected.